{% extends "admin/base_site.html" %}
{% load i18n admin_urls ralph_tags admin_static admin_list foundation_alert sitetree cache %}
{% block extrastyle %}
  {{ block.super }}
  {% if not actions_on_top and not actions_on_bottom %}
    <style>
      #changelist table thead th:first-child {width: inherit}
    </style>
  {% endif %}
{% endblock %}
{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} change-list{% if bulk_edit %} bulk-edit{% endif %}{% endblock %}
{% block coltype %}flex{% endblock %}

{% block content %}
  {% if is_popup and cl %}
    {% contextual_search_form search_url search_fields cl.opts.verbose_name  %}
  {% endif %}
  <div id="content-main">
    <form method="get" action="" id="filter-form" class="hide"></form>
    <form id="changelist-form" action="" method="post"{% if cl.formset.is_multipart %} enctype="multipart/form-data"{% endif %} novalidate>{% csrf_token %}
      <div class="row header">
        <div class="large-2 small-6 columns">
            <h1>{{ header_obj_name|capfirst }}</h1>
        </div>
        {% if not is_popup %}
          <div class="large-6 columns">
            {% views_tabs list_views %}
          </div>
        {% endif %}
        <div class="large-4 small-6 columns">
          <div class="header-toolbar">
            {% if bulk_edit %}
              <a href="{{ bulk_back_url }}" class="button secondary small">
                {% trans "Back to list" %}
              </a>
            {% endif %}
            {% if has_add_permission %}
              {% url cl.opts|admin_urlname:'add' as add_url %}
              <a class="button success small addLink" href="{% add_preserved_filters add_url is_popup to_field %}">
                {% blocktrans with cl.opts.verbose_name as name %}
                  <i class="fa fa-plus" aria-hidden="true"></i> Add {{ name }}
                {% endblocktrans %}
              </a>
            {% endif %}
            {% if not is_popup %}
              <a href="#" data-options="align:left" class="button dropdown small" data-dropdown="drop1">
                {% trans "Other actions" %}
              </a>
              {% block object-tools %}
                <ul id="drop1" class="f-dropdown" data-dropdown-content>
                  {% block object-tools-items %}
                    {% if not is_popup %}
                      <li>
                        <a href="{{recoverlist_url}}" class="recoverlink">
                          <i class="fa fa-retweet" aria-hidden="true"></i>
                          {% blocktrans with cl.opts.verbose_name_plural|escape as name %}
                            Recover deleted {{name}}
                          {% endblocktrans %}
                        </a>
                      </li>
                    {% endif %}
                    {{ block.super }}
                  {% endblock %}
                </ul>
              {% endblock %}
            {% endif %}
          </div>
        </div>
      </div>
      {% if cl.formset.errors %}
          <p class="errornote">
            {% if cl.formset.total_error_count == 1 %}
              {% alert _("Please correct the error below.") 'alert' %}
            {% else %}
              {% alert _("Please correct the errors below.") 'alert' %}
            {% endif %}
          </p>
          {{ cl.formset.non_form_errors }}
      {% endif %}
      <div class="row content with-tabs">
        {% if not bulk_edit %}
          {% block filters %}
            {% if cl.has_filters %}
              {# TODO: request.user.permissions_hash if filters respect permissions #}
              {% if not request.GET %}
                {% cache 3600 filters opts.app_label opts.model_name %}
                  <!-- cache -->
                  {% spaceless %}
                    {% include 'admin/partials/filters.html' %}
                  {% endspaceless %}
                  <!-- end cache -->
                {% endcache %}
              {% else %}
                {% include 'admin/partials/filters.html' %}
              {% endif %}
            {% endif %}
          {% endblock %}
        {% endif %}
        <div class="small-{% if has_filters %}10{% else %}12{% endif %} columns">
          {% block result_list %}
            {% if cl.formset %}
              {{ cl.formset.management_form }}
            {% endif %}
              {% result_list cl %}
            {% if action_form and actions_on_bottom and cl.show_admin_actions %}
              {% admin_actions %}
            {% endif %}
          {% endblock %}
        </div>

      </div>

      {% block pagination %}
        {% pagination cl %}
      {% endblock %}
    </form>
  </div>
{% endblock %}
{% block extra_scripts %}


  {{ block.super }}
  {% if not bulk_edit %}
    <script type="text/javascript" src="{% static 'src/js/ralph-autocomplete.js' %}"></script>
    <script type="text/javascript" src="{% static 'vendor/js/foundation-datepicker.js' %}"></script>
    <script type="text/javascript" src="{% static 'src/js/foundation-datepicker-init.js' %}"></script>
  {% endif %}
  <script type="text/javascript">
    (function($) {
      $('#searchbar').focus();
    })(ralph.jQuery);
  </script>
{% endblock %}


